// stdafx.cpp : source file that includes just the standard includes
// apns_test.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
void ShowVerifyTrustError( DWORD hr )
{
    LPSTR pszName = NULL;
    switch( hr )
    {
    case CERT_E_EXPIRED:                pszName = "CERT_E_EXPIRED";                 break;
    case CERT_E_VALIDITYPERIODNESTING:  pszName = "CERT_E_VALIDITYPERIODNESTING";   break;
    case CERT_E_ROLE:                   pszName = "CERT_E_ROLE";                    break;
    case CERT_E_PATHLENCONST:           pszName = "CERT_E_PATHLENCONST";            break;
    case CERT_E_CRITICAL:               pszName = "CERT_E_CRITICAL";                break;
    case CERT_E_PURPOSE:                pszName = "CERT_E_PURPOSE";                 break;
    case CERT_E_ISSUERCHAINING:         pszName = "CERT_E_ISSUERCHAINING";          break;
    case CERT_E_MALFORMED:              pszName = "CERT_E_MALFORMED";               break;
    case CERT_E_UNTRUSTEDROOT:          pszName = "CERT_E_UNTRUSTEDROOT";           break;
    case CERT_E_CHAINING:               pszName = "CERT_E_CHAINING";                break;
    case TRUST_E_FAIL:                  pszName = "TRUST_E_FAIL";                   break;
    case CERT_E_REVOKED:                pszName = "CERT_E_REVOKED";                 break;
    case CERT_E_UNTRUSTEDTESTROOT:      pszName = "CERT_E_UNTRUSTEDTESTROOT";       break;
    case CERT_E_REVOCATION_FAILURE:     pszName = "CERT_E_REVOCATION_FAILURE";      break;
    case CERT_E_CN_NO_MATCH:            pszName = "CERT_E_CN_NO_MATCH";             break;
    case CERT_E_WRONG_USAGE:            pszName = "CERT_E_WRONG_USAGE";             break;
    default:                            pszName = "(unknown)";                      break;
    }
    LOG1( _T("Error 0x%08X (%s) returned by CertVerifyCertificateChainPolicy!\n"), hr, pszName );
}

void ShowSecurityError( DWORD ErrCode )
{
    LPCTSTR pszName = NULL;
    switch( ErrCode ) 
    {
    case SEC_E_BUFFER_TOO_SMALL:        pszName = _T("SEC_E_BUFFER_TOO_SMALL - The message buffer is too small. Used with the Digest SSP."); break;
    case SEC_E_CRYPTO_SYSTEM_INVALID:   pszName = _T("SEC_E_CRYPTO_SYSTEM_INVALID - The cipher chosen for the security context is not supported. Used with the Digest SSP."); break;
    case SEC_E_INCOMPLETE_MESSAGE:      pszName = _T("SEC_E_INCOMPLETE_MESSAGE - The data in the input buffer is incomplete. The application needs to read more data from the server and call DecryptMessage (General) again."); break;
    case SEC_E_INVALID_HANDLE:          pszName = _T("SEC_E_INVALID_HANDLE - A context handle that is not valid was specified in the phContext parameter. Used with the Digest and Schannel SSPs."); break;
    case SEC_E_INVALID_TOKEN:           pszName = _T("SEC_E_INVALID_TOKEN - The buffers are of the wrong type or no buffer of type SECBUFFER_DATA was found. Used with the Schannel SSP."); break;
    case SEC_E_MESSAGE_ALTERED:         pszName = _T("SEC_E_MESSAGE_ALTERED - The message has been altered. Used with the Digest and Schannel SSPs."); break;
    case SEC_E_OUT_OF_SEQUENCE:         pszName = _T("SEC_E_OUT_OF_SEQUENCE - The message was not received in the correct sequence."); break;
    case SEC_E_QOP_NOT_SUPPORTED:       pszName = _T("SEC_E_QOP_NOT_SUPPORTED - Neither confidentiality nor integrity are supported by the security context. Used with the Digest SSP."); break;
    case SEC_I_CONTEXT_EXPIRED:         pszName = _T("SEC_I_CONTEXT_EXPIRED - The message sender has finished using the connection and has initiated a shutdown."); break;
    case SEC_I_RENEGOTIATE:             pszName = _T("SEC_I_RENEGOTIATE - The remote party requires a new handshake sequence or the application has just initiated a shutdown."); break;
    case SEC_E_ENCRYPT_FAILURE:         pszName = _T("SEC_E_ENCRYPT_FAILURE - The specified data could not be encrypted."); break;
    case SEC_E_DECRYPT_FAILURE:         pszName = _T("SEC_E_DECRYPT_FAILURE - The specified data could not be decrypted."); break;
    default:                            pszName = _T("UNKNOW"); break;
    }
    LOG1( _T("Error 0x%08X %s \n"), ErrCode, pszName );
}
